<template>
  <div style="display: inline-block" data-flex="cross:center">
    <svg
      :class="svgclass"
      :style="svgStyle"
      aria-hidden="true"
      @click="$emit('click')"
      v-if="!name.startsWith('el-icon')"
    >
      <use :xlink:href="iconName"></use>
    </svg>
    <i :class="name" v-else></i>
  </div>
</template>
<script>
export default {
  name: 'os-icon',
  props: {
    name: { required: true, type: String },
    clasName: String,
    rotate: { type: Number, default: 0 },
    size: { type: [String, Number], default: 24 }
  },
  computed: {
    svgclass () {
      return ('svg-icon ' + (this.clasName || '')).trim()
    },
    iconName () {
      return `#icon-${this.name}`
    },
    svgStyle () {
      return {
        transform: `rotate(${this.rotate}deg)`,
        fontSize: `${this.size}px`
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
